package com.bankcomm.creditcard.redfriday.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bankcomm.creditcard.redfriday.BaseActivity;
import com.bankcomm.creditcard.redfriday.MainActivity;
import com.bankcomm.creditcard.redfriday.R;
import com.bankcomm.creditcard.redfriday.shop.ShopTabActivity;

public class ActivityDetailActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail);

		final int index = getIntent().getIntExtra("index",
				BaseActivity.INDEX_SUPERMARKET);
		String[] titleArray = getResources().getStringArray(
				R.array.activity_array);
		// String[] detailArray = getResources().getStringArray(
		// R.array.activity_detail_array);
		String[] detailArray = new String[3];
		detailArray[0] = "至<font color=\"red\">2012年6月30日</font>止，<font color=\"red\">每周五</font>在超市刷指定交通银行信用卡，单笔消费满128元即可享该笔交易<font color=\"red\">5%刷卡金奖励</font>！交通银行白金信用卡可享<font color=\"red\">10%刷卡金奖励</font>！";
		detailArray[1] = "至<font color=\"red\">2012年4月30日</font>止，<font color=\"red\">每周五</font>至各城市参加活动的加油站内刷交通银行信用卡，单笔消费满200元即可享该笔交易<font color=\"red\">5%刷卡金奖励</font>！<font color=\"red\">指定新客户</font>自核卡之月起连续3个自然月内可享<font color=\"red\">10%刷卡金奖励</font>！交通银行白金信用卡可享<font color=\"red\">10%刷卡金奖励</font>！";
		detailArray[2] = "<item>至<font color=\"red\">2012年5月31日</font>止，首次成功申请指定交通银行信用卡的新用户，核卡之日起<font color=\"red\">45天</font>内，在活动任一<font color=\"red\">指定商户</font>单笔有积分刷卡消费满50元，即可<font color=\"red\">获赠50元</font>刷卡金！";

		String[] numArray = getResources().getStringArray(
				R.array.activity_num_array);
		String url = "";

		ImageView imgActivityLogo = (ImageView) findViewById(R.id.activity_logo);
		switch (index) {
		case BaseActivity.INDEX_SUPERMARKET:
			imgActivityLogo.setImageResource(R.drawable.supermarket_logo);
			url = "supermarket_rule.html";
			break;
		case BaseActivity.INDEX_GASSTATION:
			imgActivityLogo.setImageResource(R.drawable.gasstation_logo);
			url = "gasstation_rule.html";
			break;
		case BaseActivity.INDEX_FIFTY:
			imgActivityLogo.setImageResource(R.drawable.fifty_logo);
			url = "fifty_rule.html";
			break;
		default:
			break;
		}

		TextView titleTextView = (TextView) findViewById(R.id.header_title);
		titleTextView.setText(R.string.activity_detail);

		Button backButton = (Button) findViewById(R.id.header_back);
		backButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

		Button homeBtn = (Button) findViewById(R.id.header_home);
		homeBtn.setVisibility(View.VISIBLE);
		homeBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						MainActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			}
		});

		TextView detailTitleTextView = (TextView) findViewById(R.id.activity_detail_title);
		detailTitleTextView.setText(titleArray[index]);

		TextView numTextView = (TextView) findViewById(R.id.activity_detail_num);
		numTextView.setText(numArray[index]);

		TextView detailContentTextView = (TextView) findViewById(R.id.activity_detail_content);
		detailContentTextView.setText(Html.fromHtml(detailArray[index]));

		Button detailBtn = (Button) findViewById(R.id.activity_detail_btn);
		detailBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						ShopTabActivity.class);
				intent.putExtra("index", index);
				startActivity(intent);
			}
		});

		Button ruleBtn = (Button) findViewById(R.id.activity_rule_btn);
		final String tmpUrl = "file:///android_asset/" + url;
		ruleBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						ActivityRuleActivity.class);
				intent.putExtra("url", tmpUrl);
				startActivity(intent);
			}
		});

	}
}
